package jpb.hotspot;

import jpb.CommandArg;
import jpb.JvmArg;
import jpb.MemArg;

/**
 * A HotSpot permanent generation size argument.
 * See http://java.sun.com/docs/hotspot/gc1.4.2/faq.html.
 *
 * @author Dariusz Kordonski
 *
 */
class MaxPermSize extends JvmArg<MemArg> {

    private static final String ARG_TEMPLATE = "-XX:MaxPermSize=%s";

    MaxPermSize() {
        super(HotspotJvm.class, HotspotJvm.CustomParamNames.MAX_PERM_SIZE.toString(), MemArg.class);
    }

    @Override
    protected void validate(MemArg argValue) {
        MemArgUtil.validateMemUnit(argValue.unit(), this);
    }

    @Override
    protected CommandArg convert(MemArg argValue) {
        return CommandArg.of(formatMaxPermSize(argValue));
    }

    private String formatMaxPermSize(final MemArg argValue) {
        return String.format(ARG_TEMPLATE, MemArgUtil.formatMemArg(argValue));
    }
}
